package com.beagle.njddapp.ui.presenter;

import com.beagle.njddapp.base.ApiService;
import com.beagle.njddapp.base.BasePresenter;
import com.beagle.njddapp.base.NjOwnerApiService;
import com.beagle.njddapp.base.RetrofitHttp;
import com.beagle.njddapp.bean.MessageBean;
import com.beagle.njddapp.net.BaseOilHttpListResponse;
import com.beagle.njddapp.net.HttpResponseObserver;
import com.beagle.njddapp.net.RxSchedulers;
import com.beagle.njddapp.ui.view.LoginView;
import com.beagle.njddapp.ui.view.MessageView;

import okhttp3.RequestBody;

/**
 * @author hxx
 * @date 2021-03-02 22:33
 */
public class MessagePresenter extends BasePresenter<MessageView> {
    private NjOwnerApiService apiService;

    public MessagePresenter() {
        retrofit2.Retrofit retrofit = RetrofitHttp.provideRetrofit();
        //获取接口对象
        apiService = retrofit.create(NjOwnerApiService.class);
    }


    public void message(int size,int page){
        RequestBody body = RequestBody.create(okhttp3.MediaType.parse("application/json;charset=UTF-8"),"{}");
        apiService.message(size+"",page+"",body).compose(RxSchedulers.compose()).safeSubscribe(new HttpResponseObserver<BaseOilHttpListResponse<MessageBean>>() {
            @Override
            public void success(BaseOilHttpListResponse<MessageBean> bean) {
                if (bean!=null&&bean.results!=null){
                    getView().showMessage(bean.results);
                }
            }

            @Override
            public void error(int code, String message) {
                getView().onError(message);
            }
        });

    }
}
